'use strict';
var createItem = require('./createItem.js');
var editItem = require('./editItem.js');
var app = getApp();

function saveSelect(temporalItem, select_num) {
    var num = select_num;
    var long = select_num.length;
    if ((temporalItem.name != '') && (temporalItem.name != undefined)) {
        if ((num[0] != '') && (num[0] != undefined)) {
            if ((app.globalData.user_form[0].edit == false) || (app.globalData.user_form[0].edit == undefined)) {
                createItem('select', temporalItem);
                app.globalData.user_form[app.globalData.user_form.length - 1].options = num;
                app.globalData.user_form[app.globalData.user_form.length - 1].options_num = long;
            } else if (app.globalData.user_form[0].edit == true) {
                editItem(temporalItem);
                app.globalData.user_form[app.globalData.user_form[0].edit_num].options = num;
                app.globalData.user_form[app.globalData.user_form[0].edit_num].options_num = long;
            }
            //返回上一个页面
            wx.navigateBack({
                url: '../items'
            })
        } else {
            wx.showModal({
                title: '提示',
                content: '请至少输入一项',
                showCancel: 'false'
            })
        }
    } else {
        wx.showModal({
            title: '提示',
            content: '请输入字段名称',
            showCancel: 'false'
        })
    }
}
module.exports = saveSelect;